#include "switchboard.hpp"

#define NBYTES 4

unsigned int address[8]={0x80000010,0x80000020,0x80000030,0x80000020,0x80000020,0x80000010,0x80000020,0x80000030};
unsigned int data[8]={0x80000010,0xBADDF00D,0xFEE1DEAD,0x00000000,0xDEADFA11,0x00000000,0x00000000,0x00000000};
int op[8]={1,1,1,0,1,0,0,0};

int main() {
    SBTX tx;
    SBRX rx;

    tx.init("from_sb_to_axil.q");
    rx.init("from_axil_to_sb.q");

    // form packet

    sb_packet txp;
    for(int i=0;i<8;i++){
        for(int j=0;j<NBYTES;j++)
        {
            txp.data[j]= (data[i]>>(24-8*j)) & 0x000000ff;
        }
        txp.data[4]=op[i];
        txp.destination=address[i];
        tx.send_blocking(txp);
        if(op[i]==1)
            printf("TX packet: %s\n op=%d", sb_packet_to_str(txp, NBYTES).c_str(),op[i]);

        sb_packet rxp;
        rx.recv_blocking(rxp);
        if(op[i]==0)
         printf("RX packet: %s\n", sb_packet_to_str(rxp, NBYTES).c_str());
    }
    printf("PASS!\n");

    return 0;
}
